/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/07/25
* File: OGLRenderTT.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "OGLRenderTT.h"

OGLRenderTT::OGLRenderTT(const Dimension2Di& size)
: RenderTT(size)
, _texture(NULL)
, _fb(NULL)
{
	setup();
}

OGLRenderTT::~OGLRenderTT()
{
	safe_delete(_fb);
	safe_delete(_texture);
}

void OGLRenderTT::bind()
{
	GLuint fbo = _fb->getFBO();
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
}

void OGLRenderTT::unbind()
{
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

Texture* OGLRenderTT::getTexture() const
{
	return _texture;
}

void OGLRenderTT::setup()
{
	_texture = new OGLFBOTexture2D(_size);
	_depth_stencil_rt = new OGLDepthStencilRenderTarget(_size);

	_fb = new OGLFrameBuffer();
	

	_fb->Attach(FrameBuffer::ATT_Color0, _texture);
	_fb->Attach(FrameBuffer::ATT_DepthStencil, _depth_stencil_rt);
}